<template>
	<view>
		<cu-custom  :key="'header'+headerKey" bgColor="bg-blue-light" :isBack="true" :title="title"></cu-custom>
		<web-view :style="showNav?'margin-top: 60rpx;':''" :src="url" :progress="false">
		</web-view>
	</view>
</template>

<script>
	import store from "@/store"
	
	export default {
		onShow() {
			this.headerKey += 1;
		},
		data() {
			return {
				headerKey:0,
				showNav:store.state.hh_showNav,
				CustomBar: this.$CustomBar||70,
				title:"外部链接",
				url:"",
				userType:store.state.hh_userType
			}
		},
		onLoad: function (option) {
			if(option.headerTitle){
				this.title=option.headerTitle
			}
			let url=option.url
			if(url){
				let separator = url.indexOf('?') !== -1 ? "&" : "?";
				url=url+separator+'accessToken='+store.state.hh_token
				window.location.href=url;
			}
		},
		methods: {
		}
	}
	//popstate
	window.addEventListener('popstate', function (event) {
		console.log('popstate');
		console.log(event);
		if(ZWJSBridge) {
			try {
				ZWJSBridge.close().then((result) => {
					console.log(result);
				}).catch((error) => {
					console.log(error);
				});
			}catch (e) {
			}
		}
		if(AlipayJSBridge) {
			try {
				AlipayJSBridge.call('closeWebview')
			} catch (e) {
				console.log(e)
			}
		}
	},false);
	window.addEventListener('pageshow', function (event) {
		if(event.persisted || window.performance && window.performance.navigation.type == 2){
			console.log('window.performance.navigation.type: '+ window.performance.navigation.type)
			if(ZWJSBridge) {
				try {
					ZWJSBridge.close().then((result) => {
						console.log(result);
					}).catch((error) => {
						console.log(error);
					});
				}catch (e) {
				}
			}
			if(AlipayJSBridge) {
				try {
					AlipayJSBridge.call('closeWebview')
				} catch (e) {
					console.log(e)
				}
			}
		}
	},false);
</script>

<style>

</style>
